home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Q about the float point format......
- Date: 19 Mar 1996 09:54:46 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4imsd6INNrle@keats.ugrad.cs.ubc.ca>
- References: <s3032089.15.314E68DD@sparc13.ncu.edu.tw> <19MAR199607404893@erich.triumf.ca>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <19MAR199607404893@erich.triumf.ca>,
- P.Bennett <bennett@erich.triumf.ca> wrote:
- >In article <s3032089.15.314E68DD@sparc13.ncu.edu.tw>, s3032089@sparc13.ncu.edu.tw (Alexander PeaceLand) writes...
- >>
- >> Could I dynamicly set the digits after the float POINT?
- >>
- >> In other word... I use printf to print the float point number
- >> like 123.456789 but in the other time i only
- >> want to print 123.456 or 123.4
- >> How shall I do? Thanks! :)
- >
- >Read the printf() man pages about width and precision specifiers.
- >Try something like:
- > float f = 123.45678;
- > printf("%6.2f", f);
- >Should print 123.46
-
- He wants to do it dynamically. In that case you can use the * specifier to
- indicate that the width or precision comes from an int argument rather than
- from the format string.
-
- If you specify a field width or precision with a *, the width and precision
- arguments to convert must appear in that order, _before_ the value argument
- converted.
-
- printf("%*.*f",8,2,1.23);
- --
-
-